<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="/gaspider/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="/gaspider/easyui/themes/icon.css">
	<script type="text/javascript" src="/gaspider/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="/gaspider/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="/gaspider/easyui/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
	<table id="dg"></table>
	<div id="win"></div>
</body>
</html>
<script>
$(function(){
	function openWindow(stitle,url){
		window.$('#win').window({  
			title:stitle,
		    width:900, 
		    top:0,
		    height:500, 
		    content:'<div style="overflow:hidden;width:100%;height:100%;"><iframe src="'+url+'" frameborder="0" width="100%" height="100%"><iframe></div>',
		    modal:true   
		});
	}
	$('#dg').datagrid({    
	    url:'/gaspider/task/data.do', 
	    fit:true,
	    pagination:true,
	    rownumbers:true,
	    idField:"id",
	    striped:true,
	    fitColumns:true,
	    toolbar: [{
			iconCls: 'icon-add',
			text:'新增任务',
			handler: function(){
				openWindow('新增任务','/gaspider/webpage/task/task_add.jsp');
					
			}
		},'-',{
			iconCls: 'icon-edit',
			text:'编辑',
			handler: function(){
				var datat = $('#dg').datagrid('getChecked');
				if(datat.length!=1){
					$.messager.show({
						title:'消息',
						msg:'请选择一行进行修改。',
						timeout:1000,
						showType:'slide'
					});
				}else{
					var id = datat[0].id;
					openWindow('编辑','/gaspider/task/edit.do?id='+id);
				}
				}
		},'-',{
			iconCls: 'icon-remove',
			text:'删除',
			handler: function(){
				var datat = $('#dg').datagrid('getChecked');
				for(var m=0;m<datat.length;m++){
		
					delete datat[m].titlefilter
					delete datat[m].contentfilter
					delete datat[m].releasedatefilter
				}
				var jsonform = {
					"deltask":datat	
				}
				
				if(datat.length==0){
					$.messager.show({
						title:'消息',
						msg:'请先选择至少一行。',
						timeout:1000,
						showType:'slide'
					});
				}else{
					$.ajax({
						url:'/gaspider/task/deltask.do',
						type: "post",
						data: jsonform,
						success:function(result){
							if(result.success){
								$.messager.show({
									title:'消息',
									msg:'删除成功。',
									timeout:1000,
									showType:'slide'
								});
							}else{
								$.messager.show({
									title:'消息',
									msg:'删除失败。',
									timeout:1000,
									showType:'slide'
								});
							}
							$('#dg').datagrid('reload');
							$('#dg').datagrid('clearChecked');
						}
					});
				}
				
			}
		}],
	    columns:[[ {
	    			field:'t',
	    			checkbox:true,
	    		}, {
					field : 'id',
					title : 'id',
					hidden:true,
				}, {
					field : 'articletype',
					title : '文章类型',
					width:30,
					align:'center'
				}, {
					field : 'websitename',
					title : '网站名称',
					width:30,
					align:'center'
				}, {
					field : 'entryurl',
					title : '入口url',
					width:30,
					align:'center'
				}, {
					field : 'listsrule',
					title : '列表页规则',
					width:30,
					align:'center'
				}, {
					field : 'listsrex',
					title : '列表页正则',
					width:30,
					align:'center'
				}, {
					field : 'writingrule',
					title : '文章页规则',
					width:30,
					align:'center'
				}, {
					field : 'writingrex',
					title : '文章页正则',
					width:30,
					align:'center'
				}, {
					field : 'urlrex',
					title : '原文url抽取规则',
					width:30,
					align:'center'
				}, {
					field : 'pagerule',
					title : '分页规则',
					width:30,
					align:'center'
				}, {
					field : 'pagerex',
					title : '分页正则',
					width:30,
					align:'center'
				}, {
					field : 'pagesuffix',
					title : '分页后缀',
					width:30,
					align:'center'
				}, {
					field : 'titlerule',
					title : '标题抽取规则',
					width:30,
					align:'center'
				}, {
					field : 'contentrule',
					title : '正文抽取规则',
					width:30,
					align:'center'
				}, {
					field : 'releasedaterule',
					title : '发表日期过滤规则',
					width:30,
					align:'center'
				} ]]
	});
});
</script>